import { defineComponent, ref, type Ref, computed, type PropType } from 'vue';
<%_ if (enableTranslation) { _%>
import { useI18n } from 'vue-i18n';
<%_ } _%>

import { filterBy } from '@/shared/computables';

export default defineComponent({
  name: '<%=jhiPrefixCapitalized%>MetricsModal',
  props: {
    threadDump: {
      type: Array as PropType<any[]>,
      default: () => [],
    },
  },
  setup(props) {
    const threadDumpFilter: Ref<any> = ref('');
    const filteredThreadDump = computed(() => filterBy(props.threadDump, { filterByTerm: threadDumpFilter.value }));

    const threadDumpData = computed(() => {
      const data = {
        threadDumpAll: 0,
        threadDumpBlocked: 0,
        threadDumpRunnable: 0,
        threadDumpTimedWaiting: 0,
        threadDumpWaiting: 0,
      };
      if (props.threadDump) {
        props.threadDump.forEach(value => {
          if (value.threadState === 'RUNNABLE') {
            data.threadDumpRunnable += 1;
          } else if (value.threadState === 'WAITING') {
            data.threadDumpWaiting += 1;
          } else if (value.threadState === 'TIMED_WAITING') {
            data.threadDumpTimedWaiting += 1;
          } else if (value.threadState === 'BLOCKED') {
            data.threadDumpBlocked += 1;
          }
        });
        data.threadDumpAll = data.threadDumpRunnable + data.threadDumpWaiting + data.threadDumpTimedWaiting + data.threadDumpBlocked;
      }
      return data;
    });

    return {
      threadDumpFilter,
      threadDumpData,
      filteredThreadDump,
<%_ if (enableTranslation) { _%>
      t$: useI18n().t,
<%_ } _%>
    };
  },
  methods: {
    getBadgeClass(threadState: string): string {
      if (threadState === 'RUNNABLE') {
        return 'bg-success';
      } else if (threadState === 'WAITING') {
        return 'bg-info';
      } else if (threadState === 'TIMED_WAITING') {
        return 'bg-warning';
      } else if (threadState === 'BLOCKED') {
        return 'bg-danger';
      }
      return '';
    },
  },
});
